package com.senthink.gl.business.api.controller;

import com.senthink.gl.business.auth.AuthService;
import com.senthink.gl.business.security.JwtTokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 区域/菜单权管理Controller
 */
@Api(tags = "区域/菜单权管理Controller")
@RestController
public class AuthorityController {

    @Autowired
    private AuthService authService;
    @Autowired
    private JwtTokenUtils jwtTokenUtils;

    /**
     * 获取用户区域下的设备权限
     *
     * @return
     */
    @ApiOperation(notes = "获取用户区域下的设备权限",value = "获取用户区域下的设备权限")
    @RequestMapping(value = "${uri.authority.area}", method = RequestMethod.GET)
    public ResponseEntity<?> getAreaAuthority(@RequestHeader("${jwt.header}") String authorization) {
        String username = jwtTokenUtils.getUsernameFromAuthorizationHeader(authorization);
        return ResponseEntity.ok(authService.findAllAreaAuthoritiesByUsername(username));
    }

    /**
     * 获取用户具有除霾器权限的区域列表
     *
     * @return
     */
    @ApiOperation(notes = "获取用户具有除霾器权限的区域列表（没有用）",value = "获取用户具有除霾器权限的区域列表（没有用）")
    @RequestMapping(value = "${uri.authority.areasWithHcAuthority}", method = RequestMethod.GET)
    public ResponseEntity<?> getAreasWithHcAuthority() {
        return ResponseEntity.ok(authService.getAreasWithHcAuthority());
    }

    /**
     * 获取用户具有某设备权限的区域列表
     *
     * @return
     */
    @ApiOperation(notes = "获取用户具有某设备权限的区域列表",value = "获取用户具有某设备权限的区域列表")
    @RequestMapping(value = "${uri.authority.areasWithDeviceAuthority}", method = RequestMethod.GET)
    public ResponseEntity<?> getAreasWithDeviceAuthority(Integer deviceType) {
        return ResponseEntity.ok(authService.getAreasWithDeviceAuthority(deviceType));
    }

    /**
     * 获取用户具有权限的所有设备的区域列表
     *
     * @return
     */
    @ApiOperation(notes = "获取用户具有权限的所有设备的区域列表",value = "获取用户具有权限的所有设备的区域列表")
    @RequestMapping(value = "${uri.authority.areasWithDevicesAuthority}", method = RequestMethod.GET)
    public ResponseEntity<?> getAreasWithDevicesAuthority() {
        return ResponseEntity.ok(authService.getAreasWithDevicesAuthority());
    }
}
